package com.yanqu.road.server.cmd.activity.fouractivity;

import com.yanqu.road.pb.activity.ShareProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.fouractivity.FourActivityMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/8/5 11:05
 */
@Cmd(code = GameProtocol.S_FOUR_ACTIVITY_OP_SUCCESS_REWARD, desc = "四活动领奖")
public class FourActivityGetRewardCmd extends AbstractCommand {
    private int childType;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ShareProto.FourActivityGetRewardReqMsg msg = ShareProto.FourActivityGetRewardReqMsg.parseFrom(packet.getBytes());
        childType = msg.getChildType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = FourActivityMgr.getReward(childType, player);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            ShareProto.FourActivityGetRewardRespMsg.Builder respMsg = ShareProto.FourActivityGetRewardRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_FOUR_ACTIVITY_OP_SUCCESS_REWARD, respMsg);
        }
    }
}
